package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.entity.Link;
import com.sangeng.domain.vo.PageVo;
import com.sangeng.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/link")
public class LinkController {
    @Autowired
    private LinkService linkService;

    /**
     * 分页查询所有的友链
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<PageVo> getAllLinkAdmin(Integer pageNum,Integer pageSize,
                                             String name,String status){
        return linkService.getAllLinkAdmin(pageNum,pageSize,name,status);
    }

    /**
     * 添加友链
     * @param link
     * @return
     */
    @PostMapping
    public ResponseResult addLink(@RequestBody Link link){
        return linkService.addLink(link);
    }

    /**
     * 根据id获取友链
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<Link> getLinkById(@PathVariable Long id){
        return linkService.getLinkById(id);
    }

    /**
     * 更新友链
     * @param link
     * @return
     */
    @PutMapping
    public ResponseResult updateLink(@RequestBody Link link){
        return linkService.updateLink(link);
    }

    /**
     * 根据id删除友链
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteLinkById(@PathVariable Long id){
        return linkService.deleteLinkById(id);
    }

}
